package pluginUtils;

import java.util.ArrayList;

public class Vector4D {
	private static int STATINDICE=0;
	protected double[] coord=new double[4];
	private int indice=STATINDICE++; 
	private ArrayList<Vector4D> voisins=new ArrayList<Vector4D>();
	
	public Vector4D(){}
	
	public Vector4D(double x,double y,double z,double t){
		this.coord[0]=x; 
		this.coord[1]=y; 
		this.coord[2]=z; 
		this.coord[3]=t; 
	}
	
	public Vector4D(double[] a){
		System.arraycopy(a, 0,this.coord,0,4); 
	}
	
	public Vector4D(Vector4D orig){
		System.arraycopy(orig.coord, 0,this.coord,0,0); 
	}
	
	public int getIndice(){return this.indice; }
	
	public static double distance(Vector4D a,Vector4D b){
		double sum=0; 
		for(int i=0;i<3;i++)
			sum+=(a.coord[i]-b.coord[i])*(a.coord[i]-b.coord[i]); 
		return Math.sqrt(sum); 
	}
	
	public double get(int i){return this.coord[i];}
	
	public static Vector4D mul(Vector4D v,double a){
		return new Vector4D(a*v.coord[0],a*v.coord[1],a*v.coord[2],a*v.coord[3]); 
	}
	
	public void addVoisin(Vector4D madameBibi){
		this.voisins.add(madameBibi);
	}
	
	public ArrayList<Vector4D> getVoisins(){
		return this.voisins; 
	}

	public double squaredNorm() {
		double s=0; 
			for(int i=0;i<4;i++)s+=coord[i]*coord[i];
		return s;
	}
	public int hashCode(){return this.indice%23;}
	public boolean equals(Object o){return this.indice==((Vector4D) o).indice;}
	
	public int nbVoisins(){return this.voisins.size();} 
	
	public String toString(){
		String s=""; 
		for(int i=0;i<4;i++) s+=" "+coord[i]; 
		return s; 
	}
	
}
